<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 给元素添加了不同的key值，相当于告诉vue，这两个元素没有关系，不要进行复用 -->
      <template v-if="loginType === 'username'">
        <label>Username</label>
        <input placeholder="Enter your username" key="12" />
      </template>
      <template v-else>
        <label>Email</label>
        <input placeholder="Enter your email address" key="34" />
      </template>

      <hr />

      <button
        @click="loginType = loginType === 'username' ? '123' : 'username'"
      >
        切换
      </button>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          loginType: "username",
        },
      });
    </script>
  </body>
</html>
